package com.vodone.v1pin.core.utils
{
	import com.vodone.v1pin.core.ExternalInterfaceManager;
	import com.vodone.v1pin.core.model.MainModelLocator;
	import com.vodone.v1pin.user.pm.RegisterPM;
	
	import flash.events.Event;

	public class LoginUtil
	{
		public static function checkLogin( fun:Function = null , obj:Object = null ):void
		{
			var pm1:RegisterPM = new RegisterPM();
			pm1.addEventListener("checkLoginComplete",checkComplete);
			pm1.addEventListener("fault",falseComplete);
			pm1.checkLogin();
			
			var myFun:Function = fun;
			
			function checkComplete(event:Event ):void
			{
				var pm:RegisterPM = event.currentTarget as RegisterPM;
				var checkObj:Object = pm.checkObj;
				MainModelLocator.getInstance().debugStr += "检查是否登陆"+checkObj.data.username + "\n";
				if(checkObj && checkObj.hasOwnProperty("data") && checkObj.data.hasOwnProperty("username")){
					if( checkObj.data.username != null && checkObj.data.username != "" ){
						MainModelLocator.getInstance().userLoginVO.userId = checkObj.data.userid;
						MainModelLocator.getInstance().userLoginVO.userName = checkObj.data.username;
						MainModelLocator.getInstance().userLoginVO.isLogin = true;
						if( myFun != null ){
							if( obj ){
								myFun( true , obj );
							}else{
								myFun( true );
							}
						}
						return;
					}
				}
				
				if( myFun != null ){
					if( obj ){
						myFun( false , obj );
					}else{
						myFun( false );
					}
				}
				MainModelLocator.getInstance().userLoginVO.isLogin = false;
				MainModelLocator.getInstance().userLoginVO.userId = "";
				MainModelLocator.getInstance().userLoginVO.userName = "";
//				ExternalInterfaceManager.NavtatorURL( "index" );
			}
			
			function falseComplete():void
			{
				
			}
		}
	}
}